Skip to content

Add GetPartialObject to MTP example#3641

Merged
HiFiPhile merged 1 commit into
hathach:masterfrom
wjklimek1:mtp-get-partial-object
May 14, 2026
Merged

Add GetPartialObject to MTP example#3641
HiFiPhile merged 1 commit into
hathach:masterfrom
wjklimek1:mtp-get-partial-object

Conversation

@wjklimek1
Copy link
Copy Markdown
Contributor

Currently MTP example works fine under Windows, but Linux file explorers had problems with opening files directly from MTP drive. Copying entire file to local drive was working though.

This is most likely due to fact that Windows uses GetObject to read entire file in one transfer and Linux tries to use GetPartialObject which is not implemented in this example.

This PR fixes this problem by implementing GetPartialObject handler. Implementation is very similar to existing GetObject, but takes file offset from host into the account.

I successfully tested it on stm32f411blackpill and stm32h503nucleo under Linux Mint (command line file access and Nemo file explorer). RAM usage increased by 8 bytes, FLASH usage increased by 200 bytes on STM32H503.

Added support for GetPartialObject for better compatibility with Linux file explorers.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for the MTP GetPartialObject operation in the MTP device example so that Linux file managers (which prefer partial reads) can open files directly from the MTP drive, matching existing behavior on Windows (which uses GetObject).

Changes:

  • Register MTP_OP_GET_PARTIAL_OBJECT in the supported operations list in tusb_config.h.
  • Add fs_get_partial_object handler that mirrors fs_get_object but honors host-supplied offset/max-length parameters.
  • Handle response building for MTP_OP_GET_PARTIAL_OBJECT in tud_mtp_data_complete_cb, returning the actual number of bytes sent.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
examples/device/mtp/src/tusb_config.h Adds MTP_OP_GET_PARTIAL_OBJECT to the list of supported MTP operations.
examples/device/mtp/src/mtp_fs_example.c Registers the new handler in the dispatch table, implements fs_get_partial_object, and adds the corresponding response case in tud_mtp_data_complete_cb.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown

MemBrowse Memory Report

Top 10 targets by memory change (%) (out of 2253 targets) View Project Dashboard →

target .text .rodata .data .bss total % diff
raspberrypi_zero/mtp 60,104 → 61,512 (+1,408) 4,651 → 7,339 (+2,688) 17,072 → 17,080 (+8) 94,123 → 98,227 (+4,104) +4.4%
msp_exp430f5529lp/mtp 15,724 → 16,376 (+652) 324 → 330 (+6) 24,660 → 25,324 (+664) +2.7%
lpcxpresso11u37/mtp 16,128 → 16,496 (+368) 372 → 380 (+8) 22,868 → 23,252 (+384) +1.7%
mm900evxb/mtp 26,344 → 26,952 (+608) 3,700 → 3,716 (+16) 39,116 → 39,756 (+640) +1.6%
nutiny_nuc126v/mtp 17,012 → 17,380 (+368) 400 → 408 (+8) 23,512 → 23,896 (+384) +1.6%
raspberry_pi_pico/mtp 19,656 → 20,032 (+376) 23,244 → 23,620 (+376) +1.6%
fomu/mtp 23,920 → 24,512 (+592) 38,304 → 38,912 (+608) +1.6%
nutiny_sdk_nuc121/mtp 17,028 → 17,380 (+352) 400 → 408 (+8) 23,528 → 23,896 (+368) +1.6%
nutiny_sdk_nuc120/mtp 17,608 → 17,960 (+352) 432 → 440 (+8) 24,144 → 24,512 (+368) +1.5%
lpcxpresso51u68/mtp 18,264 → 18,616 (+352) 376 → 384 (+8) 24,660 → 25,028 (+368) +1.5%

Copy link
Copy Markdown
Collaborator

@HiFiPhile HiFiPhile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you !

@HiFiPhile HiFiPhile merged commit 7f146c9 into hathach:master May 14, 2026
297 of 298 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants